﻿using System;
using FellowshipOne.API.Base.Interfaces;
using Restify;

namespace FellowshipOne.API.Events.Sets
{
    public class AttendanceCollection : ApiSet<Model.AttendanceCollection>, IApiSet<Model.AttendanceCollection>
    {
        private const string GET_URL = "/events/v1/attendanceSummaries/{0}/attendances/";
        public AttendanceCollection(OAuthTicket ticket, string baseUrl) : base(ticket, baseUrl) { }

        protected override string GetUrl
        {
            get
            {
                return GET_URL;
            }
        }
    }

    public interface IAttendance : IApiSet<Model.Attendance>
    {
        Model.Attendance Update(Model.Attendance entity, string id, string parentId, out string requestXml);

        Model.Attendance Update(Model.Attendance entity, string id, string parentId);

    }

    public class Attendance : ApiSet<Model.Attendance>, IAttendance
    {
        private const string GET_URL = "/events/v1/attendanceSummaries/{0}/attendances/{1}";
        private const string GET_CHILD_URL = "/events/v1/attendanceSummaries/{0}/attendances/{1}";
        private const string CREATE_URL = "/events/v1/attendanceSummaries/{0}/attendances/{1}";
        private const string EDIT_URL = "/events/v1/attendanceSummaries/{0}/attendances/{1}";
        private string _parentId = string.Empty;
        public Attendance(OAuthTicket ticket, string baseUrl) : base(ticket, baseUrl) { }

        protected override string GetUrl
        {
            get
            {
                return GET_URL;
            }
        }

        protected override string CreateUrl
        {
            get
            {
                return CREATE_URL;
            }
        }

        protected override string EditUrl
        {
            get
            {
                return String.Format(EDIT_URL, _parentId, "{0}");
            }
        }

        protected override string GetChildUrl
        {
            get
            {
                return GET_CHILD_URL;
            }
        }

        public Model.Attendance Update(Model.Attendance entity, string id, string parentId, out string requestXml)
        {
            _parentId = parentId;
            return base.Update(entity, id, out requestXml);
        }

        public Model.Attendance Update(Model.Attendance entity, string id, string parentId)
        {
            _parentId = parentId;
            return base.Update(entity, id);
        }
    }
}
